<template>
  <div>
    <el-container class="main-el-contarner">
      <el-main>
        <div class="kanbao-bigbox">
          <div class="righttop-search-box">
            <el-form
              :inline="true"
              :model="param"
              label-width="100px"
              @submit.native.prevent
            >
              <!-- <el-form-item label="公告类型：" label-width="90px">
                <el-select v-model="param.warnStatus" placeholder="公告类型" size="small" style="width:150px;">
                  <el-option label="全部" value=""></el-option>
                  <el-option label="工作准备" value="1"></el-option>
                  <el-option label="维护" value="0"></el-option>
                </el-select>
              </el-form-item> -->
              <el-form-item label="" label-width="10px">
                <el-input
                  placeholder="请输入事件名称关键字检索"
                  clearable
                  v-model="param.name"
                  size="small"
                  style="width: 350px"
                  @keyup.enter.native="onSearch"
                >
                  <i slot="prefix" class="el-input__icon el-icon-search"></i>
                </el-input>
              </el-form-item>
              <el-form-item>
                <el-button type="primary" size="small" @click="onSearch">查找</el-button>
              </el-form-item>

              <el-form-item style="float: right">
                <el-button size="mini" type="primary" plain @click="handleAdd"
                  ><i class="el-icon-download"></i> 导出数据
                </el-button>
              </el-form-item>
            </el-form>
          </div>
          <div class="container-box">
            <el-table
              :data="tabledatas"
              border
              stripe
              max-height="480px"
              :header-cell-style="{
                background: '#cfcfcf',
                color: '#000000',
                'text-align': 'center',
              }"
              :cell-style="{ 'text-align': 'center' }"
              style="width: 100%"
              size="small"
              @selection-change="selectionChange"
            >
              <el-table-column
                type="selection"
                header-align="center"
                width="60"
              ></el-table-column>
              <el-table-column
                type="index"
                label="序号ID"
                :index="indexMethod"
                align="center"
                width="100"
              ></el-table-column>
              <el-table-column prop="event_name" label="事件名称"> </el-table-column>
              <el-table-column prop="inform_type" label="通知类型">
                <template #default="scope">
                  <span v-if="scope.row.inform_type == 1">故障通知</span>
                  <span v-if="scope.row.inform_type == 2">离线通知</span>
                  <span v-if="scope.row.inform_type == 3">消防通知</span>
                  <span v-if="scope.row.inform_type == 4">周界通知</span>
                  <span v-if="scope.row.inform_type == 5">周位通知</span>
                </template>
              </el-table-column>
              <el-table-column prop="inform_content" label="通知内容"> </el-table-column>
              <el-table-column
                prop="inform_time"
                label="通知时间"
                :formatter="dateFormat"
              >
              </el-table-column>
              <el-table-column prop="inform_way" label="通知方式"> </el-table-column>

              <el-table-column prop="inform_user_id" label="通知对象id" v-if="false">
              </el-table-column>

              <el-table-column prop="inform_user_name" label="通知对象">
              </el-table-column>

              <el-table-column prop="alarm_record_id" label="告警id"> </el-table-column>

              <el-table-column prop="is_read" label="已读状态">
                <template #default="scope">
                  <div>{{ scope.row.is_read === "0" ? "否" : "是" }}</div>
                </template>
              </el-table-column>

              <el-table-column prop="read_date" label="已读日期" :formatter="dateFormat">
              </el-table-column>

              <el-table-column fixed="right" label="操作" width="100">
                <template slot-scope="scope">
                  <el-button
                    v-if="scope.row.is_read == '1'"
                    disabled
                    type="text"
                    style="color: #cdc5bf; margin: 3px; padding: 0px"
                    >已确认
                  </el-button>
                  <el-button
                    v-if="scope.row.is_read == '0'"
                    @click="readClick(scope.row)"
                    type="text"
                    style="color: #18bc9c; margin: 3px; padding: 0px"
                    >确认
                  </el-button>
                </template>
              </el-table-column>

              <!-- <el-table-column
                fixed="right"
                label="操作"
                width="120">
                <template slot-scope="scope">
                  <el-button @click="delClick(scope.row)" type="text" icon="el-icon-document" style="color: #18BC9C;margin:3px;padding:0px;">详情</el-button>
                </template>
              </el-table-column> -->
            </el-table>

            <div class="pagebox">
              <el-pagination
                @size-change="sizeChange"
                @current-change="currentChange"
                :current-page="param.pageNo"
                :page-sizes="[10, 30, 50, 100, 500]"
                :page-size="param.limit"
                layout="total, sizes, prev, pager, next, jumper"
                :total="dataTotal"
              >
              </el-pagination>
            </div>
          </div>
        </div>
      </el-main>
    </el-container>
  </div>
</template>

<script>
import SideHeader from "@/views/inc/SideHeader";
import Navlanmu from "@/views/inc/Navlanmu";
import LeftMenuMessage from "@/views/inc/LeftMenuMessage";
import { getDateTimes, numFormat, getDateWeek } from "@/utils/index.js";
import { getlist, getgridsave } from "@/api/message/list";
import moment from "moment";

export default {
  name: "NoticeRecord",
  components: { SideHeader, Navlanmu, LeftMenuMessage },
  data() {
    return {
      loadingdata1: false,
      isloading: false,
      param: {
        funId: "msg_inform_records",
        baseSQL: "",
        warnStatus: "",
        name: "",
        offset: 0,
        pageNo: 1,
        limit: 10,
      },
      //   datas:[
      //   {title:'巡检工单提醒',fanwei:'234',sxtime:'2022-11-11 10:11:11',shxtime:'2023-11-12 10:11:11',ggleixing:'工作准备',dengji:'高',faburen:'张三',beizhu:'调试测试消息',status:'1'},
      //   {title:'巡检工单提醒',fanwei:'234',sxtime:'2022-11-11 10:11:11',shxtime:'2023-11-12 10:11:11',ggleixing:'工作准备',dengji:'高',faburen:'张三',beizhu:'调试测试消息',status:'1'},
      //   {title:'巡检工单提醒',fanwei:'234',sxtime:'2022-11-11 10:11:11',shxtime:'2023-11-12 10:11:11',ggleixing:'工作准备',dengji:'高',faburen:'张三',beizhu:'调试测试消息',status:'1'},
      //   {title:'巡检工单提醒',fanwei:'234',sxtime:'2022-11-11 10:11:11',shxtime:'2023-11-12 10:11:11',ggleixing:'工作准备',dengji:'高',faburen:'张三',beizhu:'调试测试消息',status:'1'},
      // ],
      dataTotal: 0,
      tabledatas: [],
      fromData: {
        funId: "msg_inform_records",
        is_iot: false,
        datas: [{}],
      },
    };
  },
  mounted() {
    //
    this.getDatas();
  },
  created() {
    this.isloading = false;
  },
  methods: {
    nodeClick(type, data) {
      this.loadingdata1 = true;
      console.log("nodeClick", type, data);
      this.searchForm = data;
      this.getEnergyQushi();
      this.getEnergyDeptRanking();
      this.getEnergylevelCount();
    },
    handleAdd() {},
    // 数据搜索按钮
    onSearch() {
      this.param.pageNo = 1;
      this.getDatas();
    },
    // 复选框按钮
    selectionChange() {
      console.log("selectionChange");
    },
    indexMethod(index) {
      return (this.param.pageNo - 1) * this.param.limit + index + 1;
    },
    sizeChange(val) {
      this.param.limit = val;
      this.getDatas();
    },
    currentChange(val) {
      this.param.pageNo = val;
      this.param.offset = (val - 1) * this.param.limit;
      this.getDatas();
    },
    getDatas() {
      if (this.param.name == "") {
        this.param.baseSQL = "";
      } else {
        this.param.baseSQL = 'event_name like "%' + this.param.name + '%"';
      }
      getlist(this.param).then((res) => {
        if (res.status == "200") {
          console.log(111123, res.data);
          let resdata = res.data;
          this.tabledatas = resdata.rows;
          this.dataTotal = resdata.total;
        }
      });
    },
    dateFormat(row, column, cellValue, index) {
      var date = row[column.property];
      if (date == undefined) {
        return "";
      }
      return moment(date).format("YYYY-MM-DD HH:mm:ss");
    },
    readClick(e) {
      this.getDatas();
      console.log(333312, e);
      this.fromData.datas[0] = e;
      this.fromData.datas[0].is_read = "1";
      this.fromData.datas[0].read_date = Date.parse(new Date());

      // this.fromData.datas[0].resolve_date = Date.parse(new Date())

      console.log(this.fromData.datas[0].resolve_date);

      this.$confirm(`是否确认当前记录(${e.alarm_records_name}), 是否继续?`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        console.log(this.fromData);
        getgridsave(this.fromData).then((res) => {
          console.log(res);
          if (res.data.code === "200") {
            console.log("ces", res.data);
            this.$message({
              message: "确认成功",
              type: "success",
            });

            this.getDatas();
          } else {
            this.$message({
              message: "确认失败",
              type: "error",
            });
          }
        });
      });
    },
  },
};
</script>
<style>
.kanbao-bigbox .el-loading-spinner .el-loading-text {
  color: #666 !important;
}
</style>
<style scoped>
.el-main {
  padding: 0px !important;
}

.kanbao-bigbox {
  margin-top: 0px;
}
</style>
<style scoped>
.righttop-search-box {
  background: #f8f8f8;
  padding: 8px 20px 7px 20px;
  border-bottom: 1px solid #ececec;
  position: fixed;
  top: 0;
  width: calc(100% - 55px);
  z-index: 4;
}

.righttop-search-box .el-form-item {
  margin-bottom: 0px !important;
}

.container-box {
  padding: 10px;
  margin: 50px 0;
}

.pagebox {
  text-align: right;
  padding: 10px;
  position: fixed;
  bottom: 0;
  right: 0;
  width: 100%;
  background-color: #ececec;
  z-index: 4;
}
</style>
